package com.yycwxt.modules.admin.fytj;

import com.yycwxt.common.ReturnResult;
import com.yycwxt.modules.admin.data_import.AccountData;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("fytj")
@Api
public class FytjController {
    private final FytjService fytjService;

    public FytjController(FytjService fytjService) {
        this.fytjService = fytjService;
    }

    @GetMapping("test")
    public List<FytjTest> selectAllTest(Integer zq) {
        return fytjService.selectAllTest(zq);
    }

    @GetMapping()
    public ReturnResult selectAll(String zq) {
        Integer pzq = null;
        if("now".equals(zq)){
            pzq = AccountData.getAccountDate();
        }
        else{
            return ReturnResult.buildFailureResult("参数格式不对，只能写 now、lastmouth、lastyear");
        }
        List<Fytj> fytjList = fytjService.selectAll(pzq);
        BigDecimal bigDecimal = new BigDecimal(0.0000);
        for (int i = 0; i < fytjList.size(); i++) {
            fytjList.get(i).setErp((fytjList.get(i).getErp() == null ? bigDecimal : fytjList.get(i).getErp()));
            fytjList.get(i).setRyfy((fytjList.get(i).getRyfy() == null ? bigDecimal : fytjList.get(i).getRyfy()));
            fytjList.get(i).setWxfy((fytjList.get(i).getWxfy() == null ? bigDecimal : fytjList.get(i).getWxfy()));
            fytjList.get(i).setDpyyfy((fytjList.get(i).getDpyyfy() == null ? bigDecimal : fytjList.get(i).getDpyyfy()));
            fytjList.get(i).setTgfy((fytjList.get(i).getTgfy() == null ? bigDecimal : fytjList.get(i).getTgfy()));

            fytjList.get(i).setWlf((fytjList.get(i).getWlf() == null ? bigDecimal : fytjList.get(i).getWlf()));
            fytjList.get(i).setZhglf((fytjList.get(i).getZhglf() == null ? bigDecimal : fytjList.get(i).getZhglf()));
            fytjList.get(i).setBcf((fytjList.get(i).getBcf() == null ? bigDecimal : fytjList.get(i).getBcf()));
            fytjList.get(i).setQtfy((fytjList.get(i).getQtfy() == null ? bigDecimal : fytjList.get(i).getQtfy()));
            fytjList.get(i).setSjxsje((fytjList.get(i).getSjxsje() == null ? bigDecimal : fytjList.get(i).getSjxsje()));
        }
        return ReturnResult.buildSuccessResult(fytjList);
    }
}
